#ifndef  __M1_CTRL_H__
#define  __M1_CTRL_H__

#ifdef __cplusplus
extern "C"
{
#endif

#include <stdint.h>

#define POLE_NUMBER		5
#define M1_CALI_EN			0

#define M1_CALI_TIME		(3000*4)

#define SPEED_LOOP			(0)
#define POSITION_LOOP			(1)


typedef enum 
{
	M1_INIT			= 0, 
	M1_CHARGE		= 1, 
	M1_WIND			= 2,
	M1_ALIGN		= 3,	
	M1_START		= 4, 
	M1_SW			= 5, 
	M1_RUN			= 6,   
	M1_STOP			= 7, 
	M1_BRAKE		= 8,
	M1_FAULT		= 9,
	M1_UNKNOWN		= 0xFF
}M1States;

typedef struct
{
	uint8_t			RunStop;
	uint8_t			MotorBack;
	uint8_t			MotorFR;
	uint8_t			MotorFR_Pre;
	uint8_t			CaliEn;
	

}struct_M1_Flag;

#define OPEN_LOOP_EN	0


#define Load_T0_Cnt()							(0xffffffff - TIMER0->TIMER0VAL) //TMR_GetTimingData(TMR0))   
#define Reset_T0_Cnt()							TMR_SetPeriod(TIMER0,0XFFFFFFFF)
#define Write_T0_Cnt(x)							TMR_SetPeriod(TIMER0,(0XFFFFFFFF -x));	TMR_Start(TIMER0)


void M1_Init(void);
void M1_Task_1ms(void);
void M1_Para_init(void);


extern volatile M1States M1_State;
extern volatile struct_M1_Flag M1_Flag;
extern volatile uint32_t M1_Speed_Ctrl_Mode;


#ifdef __cplusplus
}
#endif

#endif // __M1_CTRL_H__

